{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Virtual environment\n",
    "When working with Python projects, best practice is to have a separate virtual environment for each of them. \n",
    "\n",
    "Each virtual environment has its own Python binary. When you install some Python package into your virtual environment, it'll be installed only into that specific environment. This means that you can have different versions of a single Python package in different virtual environments in the same machine. Virtual environments are also useful if you need to use different Python versions in your projects."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## [`venv`](https://docs.python.org/3/library/venv.html#module-venv)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Creating new virtual environment\n",
    "You can create all your virtual environments into a single directory (for example, `.virtualenvs` directory inside your home folder). This makes them easier to find."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`python3 -m venv /path/to/new/environment`\n",
    "\n",
    "or\n",
    "\n",
    "`path/to/your/python -m venv /path/to/new/environment`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Activating the virtual environment"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Windows: `path_to_virtual_env\\Scripts\\activate.bat`<br/>\n",
    "Posix: `source path_to_virtual_env/bin/activate`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Installing packages\n",
    "After activating the newly created virtual environment, you can install new packages by using `pip`. For example if you want to install `pytest`:\n",
    "\n",
    "`python -m pip install pytest`\n",
    "\n",
    "it'll be installed into path_to_virtual_env/lib/<python_version>/site-packages. Note that the path to site-packages maybe slightly different depending on the operating system you are using.\n",
    "\n",
    "You can list the installed packages and their versions by running:\n",
    "\n",
    "`python -m pip freeze`"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
